package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.GroundTypeDao;
import VO.GroundType;

public class ground_type_add extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public ground_type_add() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
        String groundid = request.getParameter("groundid");
        //request.getParameter()方法传递的数据，会从Web客户端传到Web服务器端，代表HTTP请求数据
		int ground_id=Integer.parseInt(groundid);//将字符型转换为整型
        String typename = request.getParameter("groundname");
        String demo = request.getParameter("demo");
        GroundTypeDao gtdao=new GroundTypeDao();//
		GroundType gtype=new GroundType();
		gtype.setId(ground_id);     //用gtype对象得setter方法改变id的值
		gtype.setTypename(typename);
		gtype.setDemo(demo);
		gtdao.saveGroundType(gtype);
		response.sendRedirect("/Gym/ground_type_add_successed.jsp");  //重定向到添加成功的页面
	
	}
//	request.getRequestDispatcher("../ground_type_add_successed.jsp").forward(request,response);
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
